<template>
    <div>
        <div class="logo">
            <img src="~@/assets/logo2.png" alt="">
        </div>
        <div class="cubes">
            <div class="h2">全部数据库</div>
            <a-icon type="caret-down" />
            <div class="cube-list">
                <div class="item" v-for="item in cubes" :key="item.cubeId" @click="visitCube(item)">
                    {{item.cubeNameZh}}
                </div>
            </div>
        </div>
        <div class="header-nav">
            <div class="navList">
                <router-link :to="dataUrl">数据查询</router-link>
                <a-divider type="vertical" />
                <router-link to="/datas_articles">原文查看</router-link>
                <a-divider type="vertical" />
                <router-link to="/datas_reback">意见反馈</router-link>
            </div>
        </div>
        
        <div class="search">
            <a-input-search placeholder="请输入关键词" size="large" v-model="keywords" @search="onSearch">
                <a-button type="primary" slot="enterButton">
                    <a-icon type="search" />
                    搜索
                </a-button>
            </a-input-search>

            <a-button type="primary" class="cloud-btn" ghost size="large" @click="goCloud">
                云分析平台
            </a-button>
        </div>
    </div>
</template>

<script>
import { delSessionItem } from '../until/tools';
export default {
    data() {
        return {
            keywords:this.$route.query.keywords||''
        }
    },
    computed:{
        cubes() {
            let arr = this.$store.getters.getCubes;
            let result = [];
            arr.forEach(item=>{
                if(item.children.length>0&&item.visitAuth===1) {
                    result.push(item);
                }
            });            
            return result;
        },
        dataUrl() {
            let obj = {
                path:'/datas_data'
            }
            let params;
            if(this.cubes[0]) {
                if(this.cubes[0].children&&this.cubes[0].children[0]) {
                    params = {
                        pCubeId:this.cubes[0].cubeId,
                        cubeId:this.cubes[0].children[0].cubeId
                    }
                } else {
                    params = {
                        cubeId:this.cubes[0].cubeId
                    }   
                }
            }
            obj.query = params;
            return obj;
        }
    },
    methods:{
        onSearch(e) {
            if(e==='') {
                return false;
            }
            this.$router.push({
                path:'/datas_search',
                query:{keywords:e}
            })
        },
        visitCube(item) {
            let params;
            if(item.children&&item.children[0]) {
                params = {
                    pCubeId:item.cubeId,
                    cubeId:item.children[0].cubeId
                }
            } else {
                 params = {
                    cubeId:item.cubeId
                }   
            }
            delSessionItem('dims');
            this.$router.push({
                path:'/datas_data',
                query:params
            });
        },
        goCloud() {
            this.$router.push({path:'/cloud'})
        }      
    }
}
</script>

<style lang="scss">
.search {
    .ant-input {
        background:none;
        color:#fff;
    }
}
</style>
<style lang="scss" scoped>
@import '../scss/datas/header.scss';
</style>